home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEX-UTIL
/
DVI_DVI1
/
dvilj
/
c
/
dviconv
< prev
next >
Wrap
Text File
|
1996-02-20
|
18KB
|
491 lines
#include "dvilj.h"
/*-->ActualFactor*/
/**********************************************************************/
/************************** ActualFactor ****************************/
/**********************************************************************/
double /* compute the actual size factor given the approximation */
ActualFactor(long4 unmodsize) /* actually factor * 1000 */
{
double realsize; /* the actual magnification factor */
realsize = (double)unmodsize / 1000.0;
if (abs((int)(unmodsize - 1095l))<2)
realsize = 1.095445115; /*stephalf*/
else if (abs((int)(unmodsize - 1315l))<2)
realsize = 1.31453414; /*stepihalf*/
else if (abs((int)(unmodsize - 1577l))<2)
realsize = 1.57744097; /*stepiihalf*/
else if (abs((int)(unmodsize - 1893l))<2)
realsize = 1.89292916; /*stepiiihalf*/
else if (abs((int)(unmodsize - 2074l))<2)
realsize = 2.0736; /*stepiv*/
else if (abs((int)(unmodsize - 2488l))<2)
realsize = 2.48832; /*stepv*/
else if (abs((int)(unmodsize - 2986l))<2)
realsize = 2.985984; /*stepvi*/
/* the remaining magnification steps are represented with sufficient
accuracy already */
return(realsize);
}
/*-->DecodeArgs*/
/*********************************************************************/
/***************************** DecodeArgs ****************************/
/*********************************************************************/
void
DecodeArgs(int argc, char *argv[] )
{
int argind; /* argument index for flags */
char curarea[STRSIZE]; /* current file area */
char curname[STRSIZE]; /* current file name */
char *tcp, *tcp1; /* temporary character pointers */
char *this_arg;
int ddi;
double x_offset=0.0, y_offset=0.0;
#ifndef KPATHSEA
if ((tcp = getenv("TEXPXL")) != NULL) PXLpath = tcp;
#ifdef LJ_RESIDENT_FONTS
if ((tcp = getenv("TFMFONTS")) != NULL)
TFMpath = tcp;
else if ((tcp = getenv("TEXFONTS")) != NULL)
TFMpath = tcp;
#endif
#endif
argind = 1;
while (argind < argc) {
tcp = argv[argind];
if (*tcp == '-') {
++tcp;
switch (*tcp) {
#ifdef IBM3812
case 'b': /* first page from alternate casette */
FirstAlternate = _TRUE;
break;
#endif
case 'c': /* number of copies to print */
if ( sscanf(tcp + 1, "%hd", &ncopies) != 1 )
Fatal("Argument of -c is not a valid integer\n");
if (ncopies<1) {
Warning("argument of -c < 1; set to 1!");
ncopies=1;
}
break;
#ifdef DEBUG
case '-': /* - selects Debug output */
tcp++;
if (*tcp == 'D') {
Debug = _TRUE;
#ifdef KPATHSEA
sscanf (tcp + 1, "%u", &kpathsea_debug);
#endif
}
break;
#endif
#ifdef LJ2P
case 'd': /* d selects DUPLEX mode */
tcp++;
if (*tcp == '1' ) DuplexMode = 1;
else if (*tcp == '2') DuplexMode = 2;
else {
Warning("Invalid DUPLEX mode, assuming DUPLEX=1, Long-Edge Binding");
DuplexMode = 1;
}
break;
#endif
case 'D': /* D selects DoublePage */
DoublePage = _TRUE;
tcp++;
if (*tcp == '1' || *tcp == '2') {
if (*tcp == '2') PrintFirstPart = _FALSE;
else PrintSecondPart = _FALSE;
tcp++;
}
if (*tcp == '-') PrintEmptyPages = _FALSE;
break;
#ifdef LJ4
case 'E': /* do not reset printer (go) */
econoMode = _TRUE;
break;
#endif
case 'e': /* emit file is specified */
EmitFileName = ++tcp;
#ifdef MSDOS
/* delete trailing ':' (causing hangup) */
if (EmitFileName[strlen(EmitFileName)-1] == ':')
EmitFileName[strlen(EmitFileName)-1] = '\0';
#endif
#ifdef OS2 /* repeated to avoid problems with stupid c preprocessors */
/* delete trailing ':' (causing hangup) */
if (EmitFileName[strlen(EmitFileName)-1] == ':')
EmitFileName[strlen(EmitFileName)-1] = '\0';
#endif
break;
case 'f': /* next arg is starting pagenumber */
if ( sscanf(tcp + 1, "%ld", &FirstPage) != 1 )
Fatal("Argument is not a valid integer\n");
FirstPageSpecified = _TRUE;
break;
#ifdef LJ
case 'g': /* do not reset printer (go) */
ResetPrinter = _FALSE;
break;
#endif
case 'h': /* copy header file through to output */
HeaderFileName = ++tcp;
G_header = _TRUE;
break;
#if defined(LJ2P) || defined(IBM3812)
case 'l': /* landscape */
Landscape = _TRUE;
break;
#endif
#ifdef MAKETEXPK
case 'M':
/* -M, -M1 => don't make font; -M0 => do. */
makeTexPK = *(tcp + 1) == '0';
break;
#endif
case 'x': /* specify x-offset */
this_arg = 0;
if (!(*++tcp)) {
this_arg = (++argind >= argc ? 0 : argv[argind]);
} else {
this_arg = tcp;
}
if (!this_arg
|| sscanf(this_arg,"%lf", &x_offset) != 1)
Fatal("Argument of -x is not a valid floating point number\n");
break;
case 'y': /* specify y-offset */
this_arg = 0;
if (!(*++tcp)) {
this_arg = (++argind >= argc ? 0 : argv[argind]);
} else {
this_arg = tcp;
}
if (!this_arg || sscanf(this_arg, "%lf", &y_offset) != 1)
Fatal("Argument of -y is not a valid floating point number\n");
break;
case 'X': /* specify X-origin in dots */
this_arg = 0;
if (!(*++tcp)) {
this_arg = (++argind >= argc ? 0 : argv[argind]);
} else {
this_arg = tcp;
}
if (!this_arg || sscanf(this_arg,"%hd", &x_origin) != 1)
Fatal("Argument of -X is not a valid integer\n");
break;
case 'Y': /* specify Y-origin in dots */
this_arg = 0;
if (!(*++tcp)) {
this_arg = (++argind >= argc ? 0 : argv[argind]);
} else {
this_arg = tcp;
}
if (!this_arg ||
sscanf(this_arg, "%hd", &y_origin) != 1)
Fatal("Argument of -Y is not a valid integer\n");
break;
case 'm': /* specify magnification to use */
switch ( (*++tcp) ) {
case '#':
/* next arg is a magnification to use */
if ( sscanf(tcp + 1, "%ld", &usermag) != 1 )
Fatal("Argument of mag is not a valid integer\n");
break;
case '0':
usermag = 1000;
break;
case 'h':
case 'H':
usermag = 1095;
break;
case '1':
usermag = 1200;
break;
case 'q':
usermag = 1250;
break;
case '2':
usermag = 1440;
break;
case '3':
usermag = 1728;
break;
case '4':
usermag = 2074;
break;
case '5':
usermag = 2488;
break;
default:
Fatal("%c is a bad mag step\n", *tcp);
}
break;
#ifdef SUPERCOMMENT
case 'o': /* PostScript command to send */
if ( ++argind >= argc )
Fatal("No argument following -o\n", 0);
PScmd[nps++] = argv[argind];
break;
#endif
case 'p': /* print n pages */
if ( sscanf(tcp + 1, "%ld", &PrintPages) != 1 )
Fatal("Argument is not a valid integer\n");
if (PrintPages < 1)
Fatal("Argument of -p must be greater than 0\n");
break;
case 'q': /* quiet operation */
G_quiet = _TRUE;
break;
case 'r': /* switch order to process pages */
Reverse = (bool)(!Reverse);
break;
#ifdef LJ
case 's': /* specify X-origin in dots */
this_arg = 0;
if (!(*++tcp)) this_arg = (++argind >= argc ? 0 : argv[argind]);
else this_arg = tcp;
if (!this_arg || sscanf(this_arg,"%hd", &pagesize) != 1)
Fatal("Argument of -s is not a valid integer\n");
/*
* The original pgsiz_dots assumed a resolution of 300dpi. This loses
* at 600dpi so we must scale all.
*/
switch (pagesize) {
/*
* The original pgsiz_dots assumed a resolution of 300dpi. This loses
* at 600dpi so we must scale all.
*/
case 1: pgsiz_dots = 3150; break; /* executive */
case 2: pgsiz_dots = 3300; break; /* letter */
case 3: pgsiz_dots = 4200; break; /* legal */
case 26: pgsiz_dots = 3507; break; /* a4 */
case 80: pgsiz_dots = 2250; break; /* monarc */
case 81: pgsiz_dots = 2850; break; /* com10 */
case 90: pgsiz_dots = 2598; break; /* int dl */
case 91: pgsiz_dots = 2704; break; /* int c5 */
default: Fatal(
#ifndef vms
"%hd is a bad value for pagesize (1,2,3,26,80,81,90,91)",
#else
"%d is a bad value for pagesize (1,2,3,26,80,81,90,91)",
#endif
pagesize);
}
break;
#endif
case 't': /* ending pagenumber */
if ( sscanf(tcp + 1, "%ld", &LastPage) != 1 )
Fatal("Argument is not a valid integer\n");
LastPageSpecified = _TRUE;
break;
case 'v': /* verbatim mode (print pxl-file names) */
G_noverbatim = _FALSE;
break;
case 'w': /* don't print out warnings */
G_nowarn = _TRUE;
break;
#ifdef LJ
case 'z':
PrintTestPage = (bool)(!PrintTestPage);
break;
#endif
#ifdef LJ4
case 'R': /* number of copies to print */
if ( sscanf(tcp + 1, "%d", &RESOLUTION) != 1 )
Fatal("Argument of -R is not a valid integer\n");
if (RESOLUTION != 300 && RESOLUTION != 600 ) {
Warning("Resolution must be 300 or 600! Assuming 300.dpi.");
RESOLUTION=300;
} else {
if (RESOLUTION == 600) {
MFMODE = MFMODE600;
x_origin = 600;
y_origin = 600;
}
}
break;
#endif
#ifdef __riscos
case 'i': /* name of directory to store diagrams in */
tcp++; ddi=0;
while ((*tcp != ' ') && (*tcp != '\0') && (ddi < DIAGDIRSIZE-1)) {
diagdir[ddi++] = *tcp++;
}
diagdir[ddi] = '\0';
break;
case 'j': /* don't print digrams */
printdiag = _FALSE;
case 'k': /* cache diagram bitmap in document folder */
cachediag = _TRUE;
break;
#endif
default:
fprintf(ERR_STREAM, "%c is not a legal flag\n", *tcp);
}
} else {
(void) strcpy(filename, tcp);
if(!strcmp(filename, "-")) {
EmitFileName="-";
#ifdef RISC_USE_OSL
dvifp = BINOPEN("Kbd:");
#else
dvifp=stdin;
#endif
} else {
tcp = strrchr(argv[argind], '/');
/* split into directory + file name */
if (tcp == NULL) {
curarea[0] = '\0';
tcp = argv[argind];
} else {
(void) strcpy(curarea, argv[argind]);
curarea[tcp-argv[argind]+1] = '\0';
tcp += 1;
}
(void) strcpy(curname, tcp);
/* split into file name + extension */
tcp1 = strrchr(tcp, '.');
if (tcp1 == NULL) {
(void) strcpy(rootname, curname);
strcat(curname, ".dvi");
} else {
*tcp1 = '\0';
(void) strcpy(rootname, curname);
*tcp1 = '.';
}
(void) strcpy(filename, curarea);
(void) strcat(filename, curname);
if ((dvifp = BINOPEN(filename)) == FPNULL) {
/* do not insist on .dvi */
if (tcp1 == NULL) {
curname[strlen (curname) - 4] = '\0';
filename[strlen (filename) - 4] = '\0';
}
if (tcp1 != NULL || (dvifp = BINOPEN(filename)) == FPNULL) {
perror (filename);
exit (EXIT_FAILURE);
}
}
} /* dvi filename != '-" */
}
argind++;
}
#ifdef LJ4
pgsiz_dots *= (int)(RESOLUTION/300); /* rescale dots to page */
#endif
x_goffset = (short) MM_TO_PXL(x_offset) + x_origin;
y_goffset = (short) MM_TO_PXL(y_offset) + y_origin;
if (dvifp == FPNULL) {
fprintf(ERR_STREAM,"\nThis is the DVI to %s converter version %s",
PRINTER, VERSION);
#ifdef SEVENBIT
fprintf(ERR_STREAM,", 7bit");
#endif
fprintf(ERR_STREAM," (%s)\n", OS);
fprintf(ERR_STREAM,"usage: %s [OPTIONS] dvifile\n", G_progname);
fprintf(ERR_STREAM,"OPTIONS are:\n");
#ifdef DEBUG
fprintf(ERR_STREAM,"\t--D ..... turns debug output on\n");
#endif
fprintf(ERR_STREAM,
"\t-aX ..... X= searchpath leading to pixel-files (.pk or .pxl)\n");
#ifdef IBM3812
fprintf(ERR_STREAM,
"\t-b ..... take paper for first page from alternate casette\n");
#endif
fprintf(ERR_STREAM,"\t-cX ..... X= number of copies\n");
#ifdef LJ2P
fprintf(ERR_STREAM,"\t-dX ..... duplex, X=1: long-edge, 2: short-edge binding\n");
#endif
fprintf(ERR_STREAM,"\t-D ..... turns doublepage output on; ");
fprintf(ERR_STREAM,"-D1 odd pages only, -D2 even\n");
#ifdef LJ4
fprintf(ERR_STREAM,"\t-E ..... print in econo-mode\n");
#endif
fprintf(ERR_STREAM,"\t-eX ..... X= output file\n");
fprintf(ERR_STREAM,"\t-fX ..... print from begin of page number X\n");
#ifdef LJ
fprintf(ERR_STREAM,
"\t-g ..... do not reset printer at begin of job (go)\n");
#endif
fprintf(ERR_STREAM,"\t-hX ..... X= name of headerfile\n");
#ifdef __riscos
fprintf(ERR_STREAM,"\t-iX ..... name of dir to cache diagrams in\n");
fprintf(ERR_STREAM,"\t-j ..... don't print diagrams\n");
fprintf(ERR_STREAM,"\t-k ..... cache diagram bitmaps\n");
#endif
#ifdef LJ2P
fprintf(ERR_STREAM,"\t-l ..... landscape mode\n");
#endif
#ifdef MAKETEXPK
fprintf(ERR_STREAM,"\t-MX ..... Don't generate missing PK files\n");
#endif
fprintf(ERR_STREAM,"\t-mX ..... magnification X=0;h;1;2;3;4;5;#xxxx\n");
fprintf(ERR_STREAM,"\t-pX ..... print X pages\n");
fprintf(ERR_STREAM,"\t-q ..... quiet operation\n");
fprintf(ERR_STREAM,"\t-r ..... process pages in reverse order\n");
#ifdef LJ4
fprintf(ERR_STREAM,"\t-RX ..... set resolution to 300 or 600 dpi\n");
#endif
#ifdef LJ
fprintf(ERR_STREAM,"\t-sX ..... set paper size to X (see documentation)\n");
#endif
fprintf(ERR_STREAM,"\t-tX ..... print to end of page number X\n");
fprintf(ERR_STREAM,"\t-v ..... tell user which pixel-files are used\n");
fprintf(ERR_STREAM,"\t-w ..... don't print out warnings\n");
fprintf(ERR_STREAM,"\t-xX ..... X= x-offset on printout in mm\n");
fprintf(ERR_STREAM,"\t-yX ..... X= y-offset on printout in mm\n");
fprintf(ERR_STREAM,"\t-XO ..... O= x page origin in dots (default=%d)\n",
XDEFAULTOFF );
fprintf(ERR_STREAM,"\t-YO ..... O= y page origin in dots (default=%d)\n",
YDEFAULTOFF );
#ifdef LJ
fprintf(ERR_STREAM,
"\t-z ..... print test page with pagecounter after job\n");
#endif
fprintf(ERR_STREAM,
"\t- ..... dvifile is stdin (must be seekable); implies -e-\n");
exit(1);
}
if (EQ(EmitFileName, "")) {
if ((EmitFileName = (char *)malloc( STRSIZE )) != NULL)
allocated_storage += STRSIZE;
else
Fatal("Can't allocate storage of %d bytes\n",STRSIZE);
(void) strcpy(EmitFileName, curname);
if ((tcp1 = strrchr(EmitFileName, '.')))
*tcp1 = '\0';
strcat(EmitFileName, EMITFILE_EXTENSION);
}
}
/*-->DoConv*/
/*********************************************************************/
/******************************** DoConv ***************************/
/*********************************************************************/
long4
DoConv(long4 num, long4 den, int convResolution)
{
/*register*/ double conv;
conv = ((double)num / (double)den) *
((double)mag / 1000.0) *
((double)convResolution/254000.0);
return((long4) ((1.0/conv)+0.5));
}